import json

def build_vocab():
    """
    处理Json文件,读取key,并存入txt文件
    """
    chat_to_id = json.load(open('doctor_offline/ner_model/ner_data/char_to_id.json', mode='r', encoding='utf8'))
    unique_words = list(chat_to_id.keys())[1:-1]
    unique_words.insert(0, '[UNK]')
    unique_words.insert(0, '[PAD]')
    print(len(unique_words))

    # 将字写入到 data/bilstm_crf_vocab_aidoc.txt 词典文件中
    with open('doctor_offline/ner_model/ner_data/bilstm_crf_vocab_aidoc.txt', 'w') as file:
        for word in unique_words:
            file.write(word + '\n')



if __name__ == '__main__':
    build_vocab()